﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace WindowsMstsc.Models
{
    public static class GlobalVar
    {
        public static string DB_FILE
        {
            get
            {
                return Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "storage.db");
            }
        }
        /// <summary>
        /// 所有配置
        /// </summary>
        private static Dictionary<string, MstscConfig> _allConfigs;
        public static Dictionary<string, MstscConfig> AllConfigs
        {
            get
            {
                if (_allConfigs == null)
                {
                    if (!File.Exists(DB_FILE))
                    {
                        _allConfigs = new Dictionary<string, MstscConfig>();
                    }
                    else
                    {
                        string json = File.ReadAllText(DB_FILE);
                        _allConfigs = JsonSerializer.Deserialize<Dictionary<string, MstscConfig>>(json);
                    }
                }
                return _allConfigs;
            }
        }
    }
}
